package com.qfedu.edu.orderservice.controller;

import com.qfedu.edu.bo.CreateOrderBack;
import com.qfedu.edu.bo.OrderShow;
import com.qfedu.edu.orderservice.service.OrderService;
import com.qfedu.edu.result.R;
import com.qfedu.edu.vo.CreateOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * @author xiaobobo
 * @title: OrderController
 * @projectName seckill-fy-2401-parent
 * @description: TODO
 * @date 2024/11/11  11:46
 */
@RestController
@RequestMapping("/orderservice/order")
public class OrderController {

  @Autowired
  private OrderService orderService;

  /**
   * 创建订单
   * @param createOrderVo
   * @return
   */
  @PostMapping("/createOrder")
  public R createOrder(CreateOrderVo createOrderVo, HttpServletRequest req) throws UnsupportedEncodingException {
    //调用下订单的逻辑  返回订单号
    CreateOrderBack createOrderBack=orderService.createOrder(createOrderVo,req);
    return R.ok().data("orderNumber",createOrderBack.getOrderNumber()).data("userId",createOrderBack.getUserId());
  }

  /**
   * 通过订单号查询订单信息
   * @param orderNumber
   * @return
   */
  @GetMapping("/listOrderByOrderNumber")
  public R listOrderByOrderNumber(String orderNumber){
    OrderShow orderShow=orderService.listOrderByOrderNumber(orderNumber);
    return R.ok().data("order",orderShow);
  }



}
